<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>体验购物车练习</title>
</head>
<body>
    <div id="app">
        购物车：
        <ul>
        <li v-for="prod in cart">
            {{ prod.id }}. {{ prod.title }}- {{ prod.price }}
            <button @click="handleRemove(prod.id)">删除</button>
        </li>
        </ul>
    </div>
    
    <script src="./lib/vue.js"></script>
  <script>
    const vm = new Vue({
      el: '#app', // element，视图
      data: { // model 数据
        cart: new Array(6).fill(null).map((v, i) => ({
          id: i+1,
          title: '商品名称' + i,
          price: (Math.random() * 100).toFixed(2)
        }))
      },
      methods: { // 方法
        handleRemove(id) {
          this.cart = this.cart.filter(prod => prod.id !== id)
        }
      }
    })
  </script>
</body>
</html>